package com.ogilvy.audi.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.ogilvy.audi.bean.Circle;
import com.ogilvy.audi.dao.CircleDao;
import com.ogilvy.frame.hibernate.BaseDaoImpl;
import com.ogilvy.frame.page.PageTools;
@Repository
public class CircleDaoImpl extends BaseDaoImpl<Circle> implements CircleDao{
	public PageTools<Circle> selectAll(int pageNo, int pageSize){
		StringBuffer hql = new StringBuffer("from Circle");
		PageTools<Circle> plist = this.findByHql(pageNo, pageSize, hql.toString());
		return plist;
	}
	public PageTools<Circle> selectAll(int pageNo, int pageSize,Map<String,Object> condition){
		
		StringBuffer hql = new StringBuffer("from Circle where 1=1");
		if(condition.get("parentId")!=null){
			hql.append(" and parentId =").append(condition.get("parentId"));
		}
		if(condition.get("isHot")!=null){
			hql.append(" and isHot =").append(condition.get("isHot"));
		}
		
		PageTools<Circle> plist = this.findByHql(pageNo, pageSize, hql.toString());
		//PageTools<Circle> plist = null;
		return plist;
	}
	public List<Circle> selectCircles(int pageNo, int pageSize,Map<String,Object> condition){
		StringBuffer hql = new StringBuffer("from Circle where 1=1");
		if(condition.get("parentId")!=null){
			hql.append(" and parentId =").append(condition.get("parentId"));
		}
		if(condition.get("isHot")!=null){
			hql.append(" and isHot =").append(condition.get("isHot"));
		}
		if(condition.get("isNew")!=null){
			hql.append(" and isNew =").append(condition.get("isNew"));
		}
		return getSession().createQuery(hql.toString()).list();
	}
	public List<Circle> selectNewCircles(){
		return getSession().createQuery("from Circle c where c.isNew = 1").list();
	}
	public List<Circle> selectHotCircles(){
		return getSession().createQuery("from Circle c where c.isHot = 1").list();
	}
	public List<Circle> selectChidCircles(Integer parentId){
		StringBuffer hql = new StringBuffer("from Circle c where c.parentId = ").append(parentId);
		
		return getSession().createQuery(hql.toString()).list();
	}

}
